package com.example.mall.web.controller;

import com.example.mall.domain.AntiCheatConfig;
import com.example.mall.dto.AntiCheatConfigDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.AntiCheatConfigQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IAntiCheatConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/antiCheatConfig")
public class AntiCheatConfigController {

    @Autowired
    public IAntiCheatConfigService antiCheatConfigService;

    /**
     * 分页查询防作弊配置表信息
     * @param antiCheatConfigQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询防作弊配置表信息",notes = "分页查询防作弊配置表信息",httpMethod = "GET")
    public JSONResult queryPage(AntiCheatConfigQuery antiCheatConfigQuery){
        PageDTO<AntiCheatConfigDto> antiCheatConfigDtoPageDTO = antiCheatConfigService.queryPage(antiCheatConfigQuery);
        return JSONResult.success("查询成功",antiCheatConfigDtoPageDTO);
    }

    /**
     * 根据id查询防作弊配置表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询防作弊配置表信息",notes = "根据id查询防作弊配置表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.CONFIGID_NOT_ID);
        }
        AntiCheatConfig antiCheatConfig = antiCheatConfigService.getById(id);
        return JSONResult.success("查询成功",antiCheatConfig);
    }

    /**
     * 根据id查询防作弊配置表信息
     * @param id
     * @return
     */
    @GetMapping("queryAntiCheatConfigById/{id}")
    @ApiOperation(value = "根据id查询防作弊配置表信息",notes = "根据id查询防作弊配置表信息",httpMethod = "GET")
    public JSONResult queryAntiCheatConfigById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.CONFIGID_NOT_ID);
        }
        AntiCheatConfig antiCheatConfig = antiCheatConfigService.queryAntiCheatConfigById(id);
        return JSONResult.success("查询成功",antiCheatConfig);
    }

    /**
     * 查询全部防作弊配置表信息
     * @param
     * @return
     */
    @GetMapping("queryAntiCheatConfigList")
    @ApiOperation(value = "查询全部防作弊配置表信息",notes = "查询全部防作弊配置表信息",httpMethod = "GET")
    public JSONResult queryAntiCheatConfigList(){
        List<AntiCheatConfig> antiCheatConfigs = antiCheatConfigService.queryAntiCheatConfigList();
        return JSONResult.success("查询成功",antiCheatConfigs);
    }

    /**
     * 新增防作弊配置表
     * @param antiCheatConfigDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增防作弊配置表",notes = "新增防作弊配置表",httpMethod = "POST")
    public JSONResult insert(@RequestBody AntiCheatConfigDto antiCheatConfigDto){
        antiCheatConfigService.insert(antiCheatConfigDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改防作弊配置表信息
     * @param antiCheatConfigDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改防作弊配置表信息",notes = "修改防作弊配置表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody AntiCheatConfigDto antiCheatConfigDto){
        antiCheatConfigService.update(antiCheatConfigDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除防作弊配置表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除防作弊配置表信息",notes = "删除防作弊配置表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        antiCheatConfigService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除防作弊配置表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除防作弊配置表信息",notes = "批量删除防作弊配置表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        antiCheatConfigService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
